package co.gov.medellin.ssti.sub.paoyer.common.util;

import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import javax.servlet.http.HttpServletRequest;

//TODO: purge?
public class ManageSession {

	public ManageSession() {
	}

	public static void resetSessionAdjust(HttpServletRequest request,
			Collection<String> noRemovableColl) {

		Enumeration enum1 = request.getSession().getAttributeNames();

		while (enum1.hasMoreElements()) {
			String item = (String) enum1.nextElement();
			Iterator<String> noRemovableIt = noRemovableColl.iterator();
			boolean flagRemove = true;

			while (noRemovableIt.hasNext()) {
				String atrNoRemovable = noRemovableIt.next();

				if (item.equals(atrNoRemovable)) {
					flagRemove = false;
					break;
				}
			}

			if (flagRemove) {
				request.getSession().removeAttribute(item);
			}
		}
	}

	public static void resetSessionAdjust(HttpServletRequest request,
			String noRemovableAtr) {

		Enumeration enum1 = request.getSession().getAttributeNames();

		while (enum1.hasMoreElements()) {
			String item = (String) enum1.nextElement();

			if (!item.equals(noRemovableAtr)) {
				request.getSession().removeAttribute(item);
			}
		}
	}
}
